﻿using Compass.Wasm.Server.Services.Wms;
using Compass.Wasm.Shared.Wms;
using Compass.Wasm.Shared;
using Compass.WmsService.Infrastructure;
using System.ComponentModel.DataAnnotations;

namespace Compass.Wasm.Server.Controllers.Wms;

[Route("api/[controller]")]
[ApiController]
[UnitOfWork(typeof(WmsDbContext))]
public class LocationController : ControllerBase
{
    #region ctor
    private readonly ILocationService _service;
    public LocationController(ILocationService service)
    {
        _service = service;
    }
    #endregion

    #region 基本增删改查
    [HttpGet("All")]
    public async Task<ApiResponse<IEnumerable<LocationDto>>> GetAll() => await _service.GetAllAsync();

    [HttpGet("{id}")]
    public async Task<ApiResponse<LocationDto>> GetSingle([RequiredGuid] Guid id) => await _service.GetSingleAsync(id);

    [HttpPost("Add")]
    public async Task<ApiResponse<LocationDto>> Add(LocationDto dto) => await _service.AddAsync(dto);

    [HttpPut("{id}")]
    public async Task<ApiResponse<LocationDto>> Update([RequiredGuid] Guid id, LocationDto dto) => await _service.UpdateAsync(id, dto);

    [HttpDelete("{id}")]
    public async Task<ApiResponse<LocationDto>> Delete([RequiredGuid] Guid id) => await _service.DeleteAsync(id);

    #endregion

    #region 扩展查询
    [HttpGet("Name")]
    public async Task<ApiResponse<LocationDto>> GetSingleByName(string name) => await _service.GetSingleByNameAsync(name);
    //http://10.9.18.31/api/Location/Name?name=xxxx

    [HttpGet("Area")]
    public async Task<ApiResponse<IEnumerable<LocationDto>>> GetAllByArea(Warehouse_e warehouse,Area_e area, string ranks) => await _service.GetAllByAreaAsync(warehouse,area,ranks);
    //http://10.9.18.31/api/Location/Area?warehouse=xxxx&area=xxxx&ranks=ranks
    #endregion



}